import React from 'react';
import loadjs from 'loadjs';
import * as asyncLoad from '../util/asyncLoad';
import { communicationFiles, workflowPublicFiles} from '../constants/fileConfig';
import Loading from './Loading';

export default class Communication extends React.Component{
    constructor(){
        super();
        this.state = {
            hasLoad: false,
            store: null
        };
    }
    componentDidMount(){
        const init = () => {
            const { WfFormCommunicationStore } = window.weaWorkflowPublic;
            const store = new WfFormCommunicationStore();
            this.setState({hasLoad:true, store:store});
        }
        const initCommunication = () =>{
            loadjs.isDefined('communicationFiles') ? loadjs.ready('communicationFiles', init) : loadjs(communicationFiles, 'communicationFiles', init);
        }
        asyncLoad.asyncLoadModule('workflowPublic', workflowPublicFiles, initCommunication);
    }
    render(){
        const { hasLoad,store } = this.state;
        if(hasLoad){
            const { commonParam,  signReplyInfo, clearReplyInfo} = this.props;
            const { WfFormCommunicationCom } = window.weaWorkflowPublic;
            return (
              <WfFormCommunicationCom ecId={`${this && this.props && this.props.ecId || ''}_WfFormCommunicationCom@j7ap5n`}  signReplyInfo={signReplyInfo} clearReplyInfo={clearReplyInfo} WfFormCommunicationStore={store} commonParam={commonParam} />
            )
        }else{
            return (<Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@plkjph`} />);
        }
    }
}